﻿layui.use(['form', 'laydate', 'table', 'dropdown','upload'], function () {
    var form = layui.form;
    var layer = layui.layer;
    var upload = layui.upload
    var laydate = layui.laydate;
    var table = layui.table;
    var dropdown = layui.dropdown;

    //劳动关系 
    //查看加载数据
    var jbxxid = $("#jbxxid").val(); // form.val('formBasicInfo').jbxxid;
    if (jbxxid != null) {
        form.val('ldgx', {
            "jbxxid": jbxxid
        });

        var data = getldgxData(jbxxid);
        if (data.length > 0) {
            form.val('ldgx', {
                "id": data[0].id,
                "JobStatus": data[0].JobStatus,
                "LeaveDate": data[0].LeaveDate,
                "leaveNote": data[0].leaveNote,
                "WorkFiles": data[0].WorkFiles
            });

            if (data[0].JobStatus == "离职") {
                $("#leavetime").show();
                $("#leaveyy").show();
                $("#workjiaojie").show();
            }

            //加载附件列表
            if (data[0].WorkFiles != null) {
                var WorkFiles = data[0].WorkFiles.split(',');
                var lzfile=[]
                for (i = 0; i < WorkFiles.length; i++) {
                    lzfile.push({ "WorkFiles": WorkFiles[i] });
                }

                //加载数据
                table.render({
                    elem: '#tb_UpWorkFiles'
                    , cols: [[ //标题栏
                        { field: "pxxy", title: '文件名', width: 150, templet: addlzlink }
                        , { fixed: 'right', title: '操作', width: 125, minWidth: 125, toolbar: '#barlzfj' }
                    ]]
                    , data: lzfile//form.val('ldht').id)
                    , toolbar: ''
                    , even: true
                });

            }



        }
    }

    //事件监听
    table.on('tool(tb_UpWorkFiles)', function (obj) {
        var data = obj.data;
        switch (obj.event) {
            case 'showlxRec':
                var data = obj.data;//获取监听点击当前行的所有信息[object，object]
                var url = "/UploadFiles/" + data.WorkFiles;
                window.open(url);
                break;
            case 'lz_del':
                var WorkFiles = document.getElementById('WorkFiles').value;
                WorkFiles = WorkFiles.replace(data.WorkFiles, "");
                var beginstr = WorkFiles.charAt(0);
                if (beginstr == ",")
                    WorkFiles = WorkFiles.slice(1);
                var endstr = WorkFiles.substr(-1);
                if (endstr == ",")
                    WorkFiles = WorkFiles.slice(0, WorkFiles.length - 1);

                document.getElementById('WorkFiles').value = WorkFiles.replace(",,",",");
                obj.del();
                break;
        }
    });

    form.on('select(JobStat)', function (data) {
        if (data.value == "离职") {
            $("#leavetime").show();
            $("#leaveyy").show();
            $("#workjiaojie").show();
        }
        else {
            $("#leavetime").hide();
            $("#leaveyy").hide();
            $("#workjiaojie").hide();
        }
    });

    //上传工作交接表
    var uploadListIns = upload.render({
        elem: '#UpWorkFiles'
        , elemList: $('#WorkFilesList') //列表元素对象
        , url: '/upload' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
        , accept: 'file'
        , multiple: true
        , number: 3
        , auto: false
        , bindAction: '#WorkFileUP'
        , choose: function (obj) {
            var that = this;
            var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列            

            //读取本地文件
            obj.preview(function (index, file, result) {
                var tr = $(['<tr id="upload-' + index + '">'
                    //, '<td>' + file.name + '</td>'
                    , '<td><input style="border: 0;" readonly class="xcname" type="text"  value="' + file.name + '"></td>'
                    , '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>'
                    , '<td><div class="layui-progress" lay-filter="progress-demo-' + index + '"><div class="layui-progress-bar" lay-percent=""></div></div></td>'
                    , '<td>'
                    , '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
                    , '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                    , '</td>'
                    , '</tr>'].join(''));

                //单个重传
                tr.find('.demo-reload').on('click', function () {
                    obj.upload(index, file);
                });

                //删除
                tr.find('.demo-delete').on('click', function () {
                    var tags = [];
                    $(".xcname").each(function (i, e) {
                        tags[i] = $(this).val();
                    });
                    filestr = document.getElementById('WorkFiles').value;

                    filestr += "," + tags.toString();
                    filestr = filestr.replace(",,", ",");
                    document.getElementById('WorkFiles').value = filestr;
                    delete files[index]; //删除对应的文件
                    tr.remove();
                    uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                });

                that.elemList.append(tr);
                element.render('progress'); //渲染新加的进度条组件
            });

        }
        , done: function (res, index, upload) { //成功的回调
            var that = this;
            if (res.code == 0) { //上传成功
                layer.msg("上传成功！");
                var tr = that.elemList.find('tr#upload-' + index)
                    , tds = tr.children();
                tds.eq(3).html(''); //清空操作

                var tags = [];
                $(".xcname").each(function (i, e) {
                    tags[i] = $(this).val();
                });

                if (document.getElementById('WorkFiles').value != "") {
                    document.getElementById('WorkFiles').value += "," + tags.toString();
                } else {
                    document.getElementById('WorkFiles').value = tags.toString();
                }                

                delete this.files[index]; //删除文件队列已经上传成功的文件
                return;
            }
            this.error(index, upload);
        }
        , allDone: function (obj) { //多文件上传完毕后的状态回调
            console.log(obj)
        }
        , error: function (index, upload) { //错误回调
            var that = this;
            
            var tr = that.elemList.find('tr#upload-' + index)
                , tds = tr.children();
            tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
        }
        , progress: function (n, elem, e, index) { //注意：index 参数为 layui 2.6.6 新增
            element.progress('progress-demo-' + index, n + '%'); //执行进度条。n 即为返回的进度百分比
        }
    });

    //保存
    layui.$('#Save_ldgx').on('click', function () {
        if (form.val('formBasicInfo').jbxxid == "") {
            layer.msg("请先保存基本信息!");
            return;
        } else {
            form.val('ldgx', {
                "jbxxid": form.val('formBasicInfo').jbxxid
            });
        }        
        if (form.val('ldgx').JobStatus == "离职" & form.val('ldgx').LeaveDate == "") {
            layer.msg("请填写离职时间！");
            return;
        }

        var opurl = "/HmcWH/Save_ldgx";
        if (form.val('ldgx').id != "") {
            opurl = "/HmcWH/Update_ldgx";
        } else {
            form.val('ldgx', {
                "id": guiid()
            });
        }
        var data = form.val('ldgx');

        $.ajax({
            url: opurl,
            type: "post",
            async: false,
            data: data,//$("#ldgx").serialize(),
            success: function (result) {
                layer.msg(result);
                if (result == "保存失败！") {
                    form.val('ldgx', {
                        "id": ""
                    });
                }
            }
        });


    });

    function guiid() {
        return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
            function (c) {
                var r = (Math.random() * 16) | 0,
                    v = c == 'x' ? r : (r & 0x3) | 0x8;
                return v.toString(16);
            }
        );
    }

    function getldgxData(jbxxid) {
        var data = [];
        $.ajax({
            url: "/HmcWH/get_ldgx",
            type: "post",
            async: false,
            data: { "jbxxid": jbxxid },
            success: function (resut) {
                data = resut;
            }
        });
        return data;
    }

    //劳动合同
    //查看加载数据
    var jbxxid = $("#jbxxid").val();// form.val('formBasicInfo').jbxxid;

    if (jbxxid != null) {
        form.val('ldht', {
            "jbxxid": jbxxid
        });

        var data = gethtData(jbxxid, "", "last");
        if (data.length > 0) {
            form.val('ldht', {
                "id": data[0].id,
                "type": data[0].type,
                "sdate": data[0].sdate,
                "edate": data[0].edate,
                "year": data[0].year
            });

            if (data[0].type == "无固定期限劳动合同") {
                $("#e_date").hide();
            } else {
                $("#e_date").show();
            }
        }

    }

    form.on('select(htype)', function (data) {
        if (data.value == "无固定期限劳动合同") {
            $("#e_date").hide();
            form.val('ldht', {
                "year": "无固定期限"
            });
        }
        else {
            $("#e_date").show();
            form.val('ldht', {
                "year": ""
            });
        }
    });

    //加载数据
    table.render({
        elem: '#oldht'
        , cols: [[ //标题栏
            , { field: 'type', title: '合同类型', width: 150 }
            , { field: 'sdate', title: '开始时间', minWidth: 110 }
            , { field: 'edate', title: '结束时间', minWidth: 110 }
            , { field: 'year', title: '合同期限', width: 100 }
        ]]
        , data: gethtData(jbxxid, "", "")
        , even: true
    });

    //劳动合同保存
    layui.$('#Save_ldht').on('click', function () {
        form.val('ldht', {
            "jbxxid": form.val('formBasicInfo').jbxxid
        });
        var data = form.val('ldht');

        if (data.jbxxid == "") {
            layer.msg("请先保存基本信息!");
            return;
        }

        if (data.type == "") {
            layer.msg("请选择合同类型！");
            return;
        }

        if (data.year == "") {
            layer.msg("请选择合同年限！");
            return;
        }

        if (data.sdate == "") {
            layer.msg("请选择开始时间！");
            return;
        }

        if (data.type !="无固定期限劳动合同" & data.edate == "") {
            layer.msg("请选择结束时间！");
            return;
        }

        var opurl = "/HmcWH/Save_ldht";
        if (form.val('ldht').id != "") {
            opurl = "/HmcWH/Update_ldht";
        } else {
            form.val('ldht', {
                "id": guiid()
            });
        }
        data = form.val('ldht');

        $.ajax({
            url: opurl,
            type: "post",
            async: false,
            data: data,
            success: function (result) {
                if (result == "保存失败！") {
                    form.val('ldht', {
                        "id": ""
                    });
                    layer.msg(result);
                    return
                }
                layer.msg(result);
                table.reload('oldht', {
                    where: {
                        "Jbxxid": form.val('formBasicInfo').jbxxid
                    }
                })
            }
        });
    });

    function gethtData(jbxxid, ldhtid, type) {
        var data = [];
        $.ajax({
            url: "/HmcWH/get_ldht",    //后台数据请求地址
            type: "post",
            async: false,
            data: { "jbxxid": jbxxid, "ldhtid": ldhtid, "type": type },
            success: function (resut) {
                data = resut;
            }
        });
        return data;
    }

    //试用期
    //查看加载数据
    var jbxxid = $("#jbxxid").val();// form.val('formBasicInfo').jbxxid;
    if (jbxxid != null) {
        form.val('syq', {
            "jbxxid": jbxxid
        });
        var data = getsyqData(jbxxid);
        if (data.length > 0) {
            form.val('syq', {
                "id": data[0].id,
                "jbxxid": jbxxid,
                "syq": data[0].syq,
                "sdate": data[0].sdate,
                "edate": data[0].edate,
                "zzlx": data[0].zzlx,
                "zznote": data[0].zznote,
                "isjf": data[0].isjf,
                "jfdate": data[0].jfdate,
                "jfr": data[0].jfr,
                "isdb": data[0].isdb,
                "dbr": data[0].dbr,
                "dbrgx": data[0].dbrgx,
                "dbfiles": data[0].dbfiles
            });
            if (data[0].isdb == "是") {
                $("#dbw").show();
            }
            else {
                $("#dbw").hide();
            }

            //加载附件列表
            if (data[0].dbfiles != null) {
                var WorkFiles = data[0].dbfiles.split(',');
                var dbwfile = [];
                for (i = 0; i < WorkFiles.length; i++) {
                    dbwfile.push({ "dbfiles": WorkFiles[i] });
                }

                //加载数据
                table.render({
                    elem: '#tb_syq'
                    , cols: [[ //标题栏
                        { field: "dbfiles", title: '文件名', width: 200, templet: addsyqlink }
                        , { fixed: 'right', title: '操作', width: 125, minWidth: 125, toolbar: '#barsydbw' }
                    ]]
                    , data: dbwfile
                });

            }

        }

    }

    //事件监听
    table.on('tool(tb_syq)', function (obj) {
        var data = obj.data;
        switch (obj.event) {
            case 'showsyqRec':
                var data = obj.data;//获取监听点击当前行的所有信息[object，object]
                var url = "/UploadFiles/" + data.dbfiles;
                window.open(url);
                break;
            case 'syq_del':
                var dbfiles = document.getElementById('dbfiles').value;
                dbfiles = dbfiles.replace(data.dbfiles, "");
                var beginstr = dbfiles.charAt(0);
                if (beginstr == ",")
                    dbfiles = dbfiles.slice(1);
                var endstr = dbfiles.substr(-1);
                if (endstr == ",")
                    dbfiles = dbfiles.slice(0, dbfiles.length - 1);
                document.getElementById('dbfiles').value = dbfiles.replace(",,", ",");
                obj.del();
                break;
        }
    });

    form.on('select(zztype)', function (data) {
        if (data.value == "提前转正" | data.value == "延迟转正") {
            $("#zzyy").show();
        }
        else {
            $("#zzyy").hide();
        }
    });

    form.on('select(sfdb)', function (data) {
        if (data.value == "是") {
            $("#dbw").show();
        }
        else {
            $("#dbw").hide();
        }
    });

    //上传担保物附件
    var uploadListIns = upload.render({
        elem: '#UPdbfiles'
        , elemList: $('#dbfilesList') //列表元素对象
        , url: '/upload' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
        , accept: 'file'
        , multiple: true
        , number: 3
        , auto: false
        , bindAction: '#bt_dbfiles'
        , choose: function (obj) {
            var that = this;
            var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列            

            //读取本地文件
            obj.preview(function (index, file, result) {
                var tr = $(['<tr id="upload-' + index + '">'
                    //, '<td>' + file.name + '</td>'
                    , '<td><input style="border: 0;" readonly class="xcname" type="text"  value="' + file.name + '"></td>'
                    , '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>'
                    , '<td><div class="layui-progress" lay-filter="progress-demo-' + index + '"><div class="layui-progress-bar" lay-percent=""></div></div></td>'
                    , '<td>'
                    , '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
                    , '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                    , '</td>'
                    , '</tr>'].join(''));

                //单个重传
                tr.find('.demo-reload').on('click', function () {
                    obj.upload(index, file);
                });

                //删除
                tr.find('.demo-delete').on('click', function () {
                    var tags = [];
                    $(".xcname").each(function (i, e) {
                        tags[i] = $(this).val();
                    });
                    document.getElementById('dbfiles').value += "," + tags.toString();
                    delete files[index]; //删除对应的文件
                    tr.remove();
                    uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                });

                that.elemList.append(tr);
                element.render('progress'); //渲染新加的进度条组件
            });

        }
        , done: function (res, index, upload) { //成功的回调
            var that = this;
            if (res.code == 0) { //上传成功
                layer.msg("上传成功！");
                var tr = that.elemList.find('tr#upload-' + index)
                    , tds = tr.children();
                tds.eq(3).html(''); //清空操作

                var tags = [];
                $(".xcname").each(function (i, e) {
                    tags[i] = $(this).val();
                });
                document.getElementById('dbfiles').value += ","+tags.toString();

                delete this.files[index]; //删除文件队列已经上传成功的文件
                return;
            }
            this.error(index, upload);
        }
        , allDone: function (obj) { //多文件上传完毕后的状态回调
            console.log(obj)
        }
        , error: function (index, upload) { //错误回调
            var that = this;

            var tags = [];
            $(".xcname").each(function (i, e) {
                tags[i] = $(this).val();
            });
            document.getElementById('dbfiles').value = tags.toString();


            var tr = that.elemList.find('tr#upload-' + index)
                , tds = tr.children();
            tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
        }
        , progress: function (n, elem, e, index) { //注意：index 参数为 layui 2.6.6 新增
            element.progress('progress-demo-' + index, n + '%'); //执行进度条。n 即为返回的进度百分比
        }
    });

    //试用期保存
    layui.$('#Save_syq').on('click', function () {
        form.val('syq', {
            "jbxxid": form.val('formBasicInfo').jbxxid
        });
        var data = form.val('syq');

        if (data.jbxxid == "") {
            layer.msg("请先保存基本信息!");
            return;
        }

        if (data.zzlx != "正常转正" & data.zznote == "") {
            layer.msg("非正常转正，请填写原因说明！");
            return;
        }

        var opurl = "/HmcWH/Save_syq";

        if (form.val('syq').id != "") {
            opurl = "/HmcWH/Update_syq";
        } else {
            form.val('syq', {
                "id": guiid()
            });
        }
        data = form.val('syq');

        $.ajax({
            url: opurl,
            type: "post",
            async: false,
            data: data,
            success: function (result) {
                layer.msg(result);
                if (result == "保存失败！") {
                    form.val('syq', {
                        "id": ""
                    });
                }
            }
        });
    });

    function getsyqData(jbxxid) {
        var data = [];
        $.ajax({
            url: "/HmcWH/get_syq",
            type: "post",
            async: false,
            data: { "jbxxid": jbxxid },
            success: function (resut) {
                data = resut;
            }
        });
        return data;
    }

    function getNow() {
        var nowdate = new Date();
        var year = nowdate.getFullYear(),
            month = nowdate.getMonth() + 1,
            date = nowdate.getDate();

        return year + "-" + month + "-" + date;
    }

    //配置信息
    //加载数据
    var jbxxid = $("#jbxxid").val();// form.val('formBasicInfo').jbxxid;
    table.render({
        elem: '#pzxx'
        , cols: [[ //标题栏
            , { field: 'id', title: 'ID', width: 1, sort: true, hide: true }
            , { field: 'pzdate', title: '配置时间', width: 110 }
            , { field: 'pztype', title: '配置类型', minWidth: 100 }
            , { field: 'pzgsname', title: '单位', minWidth: 120 }
            , { field: 'pzbm', title: '部门', minWidth: 100 }
            , { field: 'pzgw', title: '岗位', width: 120 }
            , { field: 'xzjb', title: '行政级别', width: 120 }
            , { field: 'pznote', title: '配置说明', width: 120 }
            , { fixed: 'right', title: '操作', width: 125, minWidth: 125, toolbar: '#toolbarpzxx' }
        ]]
        , data: getpzData(jbxxid, "")
        , even: true
    });

    function getpzData(jbxxid, id) {
        var data = [];
        $.ajax({
            url: "/HmcWH/get_pzxx",    //后台数据请求地址
            type: "post",
            async: false,
            data: { "jbxxid": jbxxid, "pzxxid": id },
            success: function (resut) {
                data = resut;
            }
        });
        return data;
    }

    //培训发展
    //查看加载数据
    var jbxxid = $("#jbxxid").val();//form.val('formBasicInfo').jbxxid;
    if(jbxxid != null)
    {
        form.val('rzpx', {
        "jbxxid": jbxxid
        });
        var data = getrzpxData(jbxxid);
        if(data.length>0)
        {
            form.val('rzpx', {
                "id": data[0].id,
                "jbxxid": jbxxid,
                "rzpxr": data[0].rzpxr,
                "pxjh": data[0].pxjh
            });

            //加载附件列表
            if (data[0].pxjh != null) {
                var WorkFiles = data[0].pxjh.split(',');
                var jhfile = [];
                for (i = 0; i < WorkFiles.length; i++) {
                    jhfile.push({ "pxjh": WorkFiles[i] });
                }

                //加载数据
                table.render({
                    elem: '#tb_rzpx'
                    , cols: [[ //标题栏
                        { field: "pxjh", title: '文件名', width: 250, templet: rzpxlink }
                        , { fixed: 'right', title: '操作', width: 125, minWidth: 125, toolbar: '#barrzpx' }
                    ]]
                    , data: jhfile//form.val('ldht').id)
                    , toolbar: ''
                    , even: true
                });

            }

        }
    }

    //事件监听
    table.on('tool(tb_rzpx)', function (obj) {
        var data = obj.data;
        switch (obj.event) {
            case 'showPxjh':
                var data = obj.data;//获取监听点击当前行的所有信息[object，object]
                var url = "/UploadFiles/" + data.pxjh;
                window.open(url);
                break;
            case 'rzpx_del':
                var pxjh = document.getElementById('pxjh').value;
                pxjh = pxjh.replace(data.pxjh, "");
                var beginstr = pxjh.charAt(0);
                if (beginstr == ",")
                    pxjh = pxjh.slice(1);
                var endstr = pxjh.substr(-1);
                if (endstr == ",")
                    pxjh = pxjh.slice(0, pxjh.length - 1);
                document.getElementById('pxjh').value = pxjh.replace(",,", ",");
                obj.del();
                break;
        }
    });

    //上传培训计划
    var uploadListIns = upload.render({
        elem: '#UPpxjh'
        , elemList: $('#pxjhList') //列表元素对象
        , url: '/upload' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
        , accept: 'file'
        , multiple: true
        , number: 3
        , auto: false
        , bindAction: '#bt_UPpxjh'
        , choose: function (obj) {
            var that = this;
            var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列            

            //读取本地文件
            obj.preview(function (index, file, result) {
                var tr = $(['<tr id="upload-' + index + '">'
                    //, '<td>' + file.name + '</td>'
                    , '<td><input style="border: 0;" readonly class="xcname" type="text"  value="' + file.name + '"></td>'
                    , '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>'
                    , '<td><div class="layui-progress" lay-filter="progress-demo-' + index + '"><div class="layui-progress-bar" lay-percent=""></div></div></td>'
                    , '<td>'
                    , '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
                    , '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                    , '</td>'
                    , '</tr>'].join(''));

                //单个重传
                tr.find('.demo-reload').on('click', function () {
                    obj.upload(index, file);
                });

                //删除
                tr.find('.demo-delete').on('click', function () {
                    delete files[index]; //删除对应的文件
                    tr.remove();
                    uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                });

                that.elemList.append(tr);
                element.render('progress'); //渲染新加的进度条组件
            });

        }
        , done: function (res, index, upload) { //成功的回调
            var that = this;
            if (res.code == 0) { //上传成功
                layer.msg("上传成功！");
                var tr = that.elemList.find('tr#upload-' + index)
                    , tds = tr.children();
                tds.eq(3).html(''); //清空操作

                var tags = [];
                $(".xcname").each(function (i, e) {
                    tags[i] = $(this).val();
                });
                document.getElementById('pxjh').value += ","+tags.toString();

                delete this.files[index]; //删除文件队列已经上传成功的文件
                return;
            }
            this.error(index, upload);
        }
        , allDone: function (obj) { //多文件上传完毕后的状态回调
            console.log(obj)
        }
        , error: function (index, upload) { //错误回调
            var that = this;

            var tags = [];
            $(".xcname").each(function (i, e) {
                tags[i] = $(this).val();
            });
            document.getElementById('pxjh').value = tags.toString();


            var tr = that.elemList.find('tr#upload-' + index)
                , tds = tr.children();
            tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
        }
        , progress: function (n, elem, e, index) { //注意：index 参数为 layui 2.6.6 新增
            element.progress('progress-demo-' + index, n + '%'); //执行进度条。n 即为返回的进度百分比
        }
    });

    //入职培训保存
    layui.$('#Save_rzpx').on('click', function () {
        form.val('rzpx', {
            "jbxxid": form.val('formBasicInfo').jbxxid
        });
        var data = form.val('rzpx');

        if (data.jbxxid == "") {
            layer.msg("请先保存基本信息!");
            return;
        }

        if (data.rzpxr == "") {
            layer.msg("请填写入职引导人");
            return;
        }

        var opurl = "/HmcWH/Save_rzpx";
        if (form.val('rzpx').id != "") {
            opurl = "/HmcWH/Update_rzpx";
        } else {
            form.val('rzpx', {
                "id": guiid()
            });
        }
        data = form.val('rzpx');

        $.ajax({
            url: opurl,
            type: "post",
            async: false,
            data: data,
            success: function (result) {
                layer.msg(result);
                if (result == "保存失败！") {
                    form.val('rzpx', {
                        "id": ""
                    });
                }
            }
        });
    });

    function getrzpxData(jbxxid) {
        var data = [];
        $.ajax({
                url: "/HmcWH/get_rzpx",
            type: "post",
            async: false,
            data: { "jbxxid": jbxxid},
            success: function (resut) {
                data = resut;
            }
        });
        return data;
    }

    function get_OrgUsers() {
        var data = [];
        $.ajax({
                url: "/HmcWH/get_OrgUsers",
            type: "post",
            async: false,
            success: function (resut) {
                data = resut;
            }
        });
        return data;
    }

    //入职培训
    //加载数据
    var jbxxid = $("#jbxxid").val();// form.val('formBasicInfo').jbxxid;

    table.render({
        elem: '#qtpx'
        , cols: [[ //标题栏
            , { field: 'id', title: 'ID', width: 1, sort: true, hide: true }
            , { field: 'pxdate', title: '培训时间', width: 120 }
            , { field: 'pxname', title: '培训主题', minWidth: 120 }
            , { field: 'pxr', title: '培训讲师', minWidth: 120 }
            , { fixed: 'right', title: '操作', width: 125, minWidth: 125, toolbar: '#toolbarqtpx' }
        ]]
        , data: getqtpxData(jbxxid, "")//form.val('ldht').id)
        , even: true
    });

    function getqtpxData(jbxxid, qtpxid) {
        var data = [];
        $.ajax({
            url: "/HmcWH/get_qtpx",
            type: "post",
            async: false,
            data: { "jbxxid": jbxxid, "qtpxid": qtpxid },
            success: function (resut) {
                data = resut;
            }
        });
        return data;
    }

    //外部培训
    //加载数据
    var jbxxid = $("#jbxxid").val();// form.val('formBasicInfo').jbxxid;
    table.render({
        elem: '#wbpx'
        , cols: [[ //标题栏
            , { field: 'id', title: 'ID', width: 1, sort: true, hide: true }
            , { field: 'pxdate', title: '培训时间', width: 120 }
            , { field: 'pxname', title: '培训主题', minWidth: 120 }
            , { field: 'pxgs', title: '培训机构', minWidth: 120 }
            , { field: 'pxr', title: '培训讲师', minWidth: 120 }
            , { field: 'pxfy', title: '培训费用', minWidth: 120 }
            , { field: 'isxy', title: '是否签订培训协议', minWidth: 120 } 
            , { field: 'note', title: '未签订协议原因说明', minWidth: 200 }   
            , { field: 'pxqx', title: '培训协议服务期限', minWidth: 150 }
            , { field: 'pxxy', title: '培训协议附件', minWidth: 120, templet: addwbpxlink }
            , { fixed: 'right', title: '操作', width: 125, minWidth: 125, toolbar: '#toolbarwbpx' }
        ]]
        , data: getwbpxData(jbxxid, "")
        , even: true
    });

    function getwbpxData(jbxxid, wbpxid) {
        var data = [];
        $.ajax({
            url: "/HmcWH/get_wbpx",
            type: "post",
            async: false,
            data: { "jbxxid": jbxxid, "wbpxid": wbpxid },
            success: function (resut) {
                data = resut;
            }
        });
        return data;
    }

    //证书信息
    //加载数据
    var jbxxid = $("#jbxxid").val();// form.val('formBasicInfo').jbxxid;
        
    table.render({
        elem: '#zsxx'
        , cols: [[ //标题栏
            , { field: 'id', title: 'ID', width: 1, sort: true, hide: true }
            , { field: 'zsname', title: '证书名称', width: 300 }
            , { field: 'getdate', title: '取得时间', minWidth: 120 }
            , { field: 'zsfj', title: '证书附件', minWidth: 120, templet: addzsxxlink }
            , { fixed: 'right', title: '操作', width: 125, minWidth: 125, toolbar: '#toolbarzsxx' }
        ]]
        , data: getzsxxData(jbxxid, "")
        , even: true
    });

    function getzsxxData(jbxxid, zsxxid) {
        var data = [];
        $.ajax({
            url: "/HmcWH/get_zsxx",
            type: "post",
            async: false,
            data: { "jbxxid": jbxxid, "zsxxid": zsxxid },
            success: function (resut) {
                data = resut;
            }
        });
        return data;
    }




});

var rzpxlink = function (d) {
    var html = '<div><a rel="nofollow" style="color:#1E9FFF" href="javascript:void(0);" lay-event="showPxjh">' + d.pxjh + '</a></div>';
    return html
}

var addlzlink = function (d) {
    var html = '<div><a rel="nofollow" style="color:#1E9FFF" href="javascript:void(0);" lay-event="showlxRec">' + d.WorkFiles + '</a></div>';
    return html
}

var addsyqlink = function (d) {
    var html = '<div><a rel="nofollow" style="color:#1E9FFF" href="javascript:void(0);" lay-event="showsyqRec">' + d.dbfiles + '</a></div>';
    return html
}

function addwbpxlink(d) {
    var proofPicture = d.pxxy;
    var i, count = 0;
    var str = [], aaa = [];
    if ('' == proofPicture || null == proofPicture || undefined == proofPicture) {
        return '';
    }
    if (proofPicture.length > 0) {
        str = proofPicture.split(",");
        for (i = 0; i < proofPicture.length; i++) {
            if (proofPicture[i] == ",") { count += 1; }
        }
        for (j = 0; j < count + 1; j++) {
            aaa += '<a class="layui-blue" href="../UploadFiles/' + str[j] + '" target="_blank">' + str[j] + '</a><br/>';
        }

        return aaa;
    }
}

function addzsxxlink(d) {
    var proofPicture = d.zsfj;
    var i, count = 0;
    var str = [], aaa = [];
    if ('' == proofPicture || null == proofPicture || undefined == proofPicture) {
        return '';
    }
    if (proofPicture.length > 0) {
        str = proofPicture.split(",");
        for (i = 0; i < proofPicture.length; i++) {
            if (proofPicture[i] == ",") { count += 1; }
        }
        for (j = 0; j < count + 1; j++) {
            aaa += '<a class="layui-blue" href="../UploadFiles/' + str[j] + '" target="_blank">' + str[j] + '</a><br/>';
        }

        return aaa;
    }
}